package com.nowcoder.面试必刷101;

import java.util.Arrays;

/**
 * @Description:
 * @author： yeswater
 * @create： 2024/6/13
 */

public class BM99 {
	public static void main(String[] args) {
		int[][] arr = {{1, 2, 3},{4, 5, 6},{7, 8, 9}};
		int[][] res = rotateMatrix(arr, 3);
		System.out.println(Arrays.toString(res[0]));
		System.out.println(Arrays.toString(res[1]));
		System.out.println(Arrays.toString(res[2]));
	}
	
	/**
	 * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
	 *
	 *
	 * @param mat int整型二维数组 
	 * @param n int整型 
	 * @return int整型二维数组
	 */
	static public int[][] rotateMatrix (int[][] mat, int n) {
		if(n == 0) {
			return mat;
		}
		int[][] res = new int[n][n];
		for(int i=0; i<n; i++){
			for (int j=0; j<n; j++){
				res[j][n-i-1] = mat[i][j];
			}
		}
		return res;
	}
}
